package com.sayimo.maker.mall.orders.dao.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sayimo.framework.database.mybatis.AbstractMybatisBaseDao;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao;
import com.sayimo.maker.mall.orders.vo.OrdersGoodsInfo;



@Repository(value="ordersGoodsInfoInterfaceDao")
public class OrdersGoodsInfoInterfaceImplDao extends AbstractMybatisBaseDao<OrdersGoodsInfo> implements OrdersGoodsInfoInterfaceDao{

	@Override
	public Integer insertOrdersGoodsInfo(OrdersGoodsInfo ordersGoodsInfo) throws DaoException {
		return mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.insertOrdersGoodsInfo", ordersGoodsInfo);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public List queryOrdersGoodsInfosByBatchCode(String batchCode) throws DaoException {
		return mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryOrdersGoodsInfosByBatchCode", batchCode);
	}

	@Override
	public OrdersGoodsInfo queryOrdersGoodsInfoById(Integer id) throws DaoException {
		return mybatisInterfaceBaseDao.get("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryOrdersGoodsInfoById", id);
	}
	/**
	 * 
	* @Title: queryOrdersGoodsInfoByOrderId 
	* @Description: 查询订单下商品信息
	* @param orderId
	* @return
	* @throws DaoException
	* @return List
	* @throws
	 */
	@Override
	public List queryOrdersGoodsInfoByOrderId(Integer orderId)
			throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryOrdersGoodsInfoByOrderId", orderId);
	}

	/**
	 * 
	* @Title: updateOrderGoodsInfo 
	* @Description: 修改订单商品信息
	* @param goodsInfo
	* @return
	* @throws DaoException
	* @return Integer
	* @throws
	 */
	public Integer updateOrderGoodsInfo(OrdersGoodsInfo goodsInfo) throws DaoException {
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.updateOrderGoods", goodsInfo);
	}

	public List<OrdersGoodsInfo> queryOrdersGoodsInfoByOrdersId(Integer ordersId) throws DaoException {
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryOrdersGoodsInfoByOrdersId", ordersId);
	}

	/**
	 * 
	* @Title: queryGoodsLogist 
	* @Description: 查询商品是否支持发货到指定地址
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	public Map queryGoodsLogist(Map<String, Object> param) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryMap("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryGoodsLogist", "costMap", param);
	}

	public BigDecimal  getLogisticsCostByAreaCode(String areaCode,Integer goodsId,Integer logisticsCostId, Integer buyNum) throws DaoException{
		Map<String, Object> param = new HashMap<>();
		param.put("goodsId", goodsId);
		param.put("endAreaCode", areaCode);
		param.put("logisticsCostId", logisticsCostId);
		param.put("buyNum", buyNum);
		return (BigDecimal) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.getLogisticsCostByAreaCode", param);
	}
	
	/**
	  * 
	* @Title: queryGoodsInfoByOrderId 
	* @Description: 根据订单id获取订单下得信息
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	@Override
	public List queryGoodsInfoByOrderId(Integer orderId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryGoodsInfoByOrderId",orderId);
	}
	
	/**
	  * 
	* @Title: queryGoodsInfoByOrderId 
	* @Description: 更新订单下商品的状态
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	@Override
	public Integer updateGoodsStatus(Map<String, Object> paramMap) throws DaoException {
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.updateGoodsStatus",paramMap);
	}
	
	/**
	  * 
	* @Title: queryGoodsInfoByOrderId 
	* @Description: 根据订单号查询订单下商品个数
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	@Override
	public Integer queryCountByOrderId(Integer orderId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryCountByOrderId", orderId);
	}
	
	/**
	  * 
	* @Title: queryGoodsInfoByOrderId 
	* @Description:根据订单号和状态查询商品个数
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	@Override
	public Integer queryCountByStatus(Map<String, Object> paramMap) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryCountByStatus",paramMap);
	}
	
	/**
	  * 
	* @Title: queryGoodsInfoByOrderId 
	* @Description:根据订单号查询相关信息
	* @param param
	* @return
	* @throws DaoException
	* @return Map
	* @throws
	 */
	@Override
	public List queryInfoByOrderId(Integer orderId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.queryInfoByOrderId",orderId);
	}

	/** 
	  * @package com.sayimo.school.mall.service.ope
	  * @author chenpy
	  * @Title:  insertOrderGoodsInfo
	  * @Description: 添加订单商品
	  * @param 
	  * @throws 
	  * @return int
	  * @date 2016年6月22日
	  */
	@Override
	public void insertProviderOrderGoodsInfo(OrdersGoodsInfo goodsInfo)
			throws DaoException {
		 this.mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.insertProviderOrdersGoodsInfo", goodsInfo);
//		return this.mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.insertProviderOrderGoodsInfo",goodsInfo);
	}
	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 查询订单的总金额（没有运费 ）
	  * @param 
	  * @throws 
	  * @return BigDecimal
	  * @date 2016年7月26日
	  */ 
	public BigDecimal getOrdersTotalAmount(Map<String, Object> paramMap) throws DaoException{
		return (BigDecimal) mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.getOrdersTotalAmount", paramMap);
	}
	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 查询按件收费的商品的运费最大值
	  * @param 
	  * @throws 
	  * @return Map
	  * @date 2016年7月26日
	  */ 
	public Map getLogisticsGoodsId(Map<String, Object> paramMap) throws DaoException{
		return this.mybatisInterfaceBaseDao.queryMap("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.getLogisticsGoodsId", "tmp", paramMap);
	}
	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 批量修改订单商品信息
	  * @param 
	  * @throws 
	  * @return Integer
	  * @date 2016年7月27日
	  */ 
	public Integer batchUpdateOrdersGoodsInfos(List goodsInfos) throws DaoException{
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.batchUpdateOrdersGoodsInfos", goodsInfos);
	}
	 /**
	 * @Package com.sayimo.maker.mall.orders.dao.impl
	 * @Author 龚益君
	 * @MethodName:getPriceByProviderId
	 * @Description:
	 * @param providerId
	 * @return
	 * @throws DaoException
	 * @Date 2017年2月21日,下午4:27:11
	 */
	@Override
	public Map<String, Object> getPriceByProviderId(Integer providerId) throws DaoException {
		
		return (Map<String, Object>) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersGoodsInfoInterfaceDao.getPriceByProviderId", providerId);
	}
}
